home *** CD-ROM | disk | FTP | other *** search
- Path: solon.com!not-for-mail
- From: johnb@pivotal-dm.ccmail.compuserve.com (John Bain)
- Newsgroups: comp.lang.c,comp.lang.c.moderated
- Subject: Re: Integral promotion problem
- Date: 11 Mar 1996 06:28:36 -0600
- Organization: Pivotal Technologies Ltd.
- Sender: clc@solutions.solon.com
- Approved: clc@solutions.solon.com
- Message-ID: <4i169k$ht@solutions.solon.com>
- References: <31404525.26295649@dub-news-svc-3.compuserve.com>
- NNTP-Posting-Host: solutions.solon.com
- X-Newsreader: Forte Agent .99d/32.182
-
-
- tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya) wrote:
-
- > In article <4hqedq$1mj@solutions.solon.com>
- > johnb@pivotal-dm.ccmail.compuserve.com (John Bain) writes:
- >
- > JB: The hex values and the result of the first "if" are the "surprising"
- > JB: results I was expecting. However, the result of the second "if" has me
- > JB: confused.
- > JB:
- > JB: What am I missing?
- > JB:
- >
- > Compiler error?
-
- I'm glad it's the compiler, not me!
-
- >
- > JB: (In case it's relevent, the implementation defines the conversion of an
- > JB: unsigned integer to a signed integer, when the unsigned value cannot be
- > JB: represented in the signed integer, as being performed by truncation of
- > JB: the most significant bits if the signed integer is shorter, and then
- > JB: interpreting the remaining bits as a 2's complement integer.)
- >
- > Why should that be relevant? What am I missing?
-
- I didn't think it was relevant, it's just that the results I was seeing
- were making me doubt my understanding so I thought I'd include the
- information just in case. The reference section of K&R2 (the best
- definition I have, as I do not have a copy of the standard) says, in its
- definition of '~' (A7.4.6):
-
- "The integral promotions are performed. If the operand is unsigned, the
- result is computed by subtracting the value from the largest value of
- the promoted type. If the operand is signed, the result is computed by
- converting the promoted operand to the corresponding unsigned type,
- applying ~, and converting it back to the unsigned type."
-
- I didn't believe that the implementation defined unsigned->signed
- conversions were happening, but I didn't believe the results I was
- seeing either!
-
- Incidentally, I assume that when it says "if the operand is unsigned" it
- means _before_ promotion?
-
- > Cheers
- > Tanmoy
-
- Thanks,
-
- John
- -----------------------------------------------------------------
- John Bain
- johnb@pivotal-dm.ccmail.compuserve.com
- -----------------------------------------------------------------
-